<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>script.aculo.us Unit test file</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="javascripts/prototype.js" type="text/javascript"></script>
  <script src="javascripts/scal.js" type="text/javascript"></script>
  <script src="javascripts/scalplanner.js" type="text/javascript"></script>
  <script src="javascripts/unittest.js" type="text/javascript"></script>
  <link rel="stylesheet" href="styles/test.css" type="text/css" />
  <link rel="stylesheet" href="styles/scal.css" type="text/css" />
</head>
<body>
<h1>script.aculo.us Unit test file</h1>
<p>
  Tests for scal calendar.
</p>

<!-- Log output -->
<div id="testlog"> </div>

<div class="calbutton" onclick="Cal.toggleCalendar();" style="float:left; cursor: pointer;">Toggle Calendar</div><br />
<input type="text" id="samplecal_value" name="samplecal_value" />
<div id="samplecal" class="dashblack" style="display: none;"></div>
<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
    var upd = function(d){ $('samplecal_value').value = d.format('mm-dd-yyyy'); };

  
    new Test.Unit.Runner({
        testScal: function() { with(this) {
            $('samplecal').show();

            var options = ({titleformat:'mmmm yyyy',
                closebutton:'Y',
                dayheadlength:2,
                weekdaystart:0,
                month:5,
                year:2020,
                day:4,
                dayheadlength:3,
                prevbutton: 'P',
                nextbutton: 'N',
				planner:[]
                });
            var Cal = new scal('samplecal',upd,options);
            assertInstanceOf(scal, Cal); 
            // init date test based on options
            assertEqual('May 2020', $('samplecal').select('.caltitle')[0].innerHTML);
            // day select same as option day
            assertEqual(4, $('samplecal').select('.dayselected')[0].down().innerHTML);
            
            // make sure we have 6 weeks
            var days = $('samplecal').select('.dayboxdate');
            assertEqual(42,days.size());
            assertEqual('Sun,Mon,Tue,Wed,Thu,Fri,Sat', $('samplecal').select('.dayboxname').collect(function(h){ return h.innerHTML; }).toString());
            // make sure all day values are numeric
            days.collect(function(h){ return h.innerHTML.strip(); }).each(function(val) {
                assertMatch(/^\d+$/,val);
            });
            assertEqual('N', $('samplecal').select('.calnextmonth')[0].innerHTML);
            assertEqual('P', $('samplecal').select('.calprevmonth')[0].innerHTML);
            assertEqual('Y', $('samplecal').select('.calclose')[0].innerHTML);
            Event.simulateMouse($('samplecal').select('.calnextmonth')[0], 'click');
            assertEqual('June 2020', $('samplecal').select('.caltitle')[0].innerHTML);
            
            // make sure we have 6 weeks
            var days = $('samplecal').select('.dayboxdate');
            assertEqual(42,days.size());
            var prev = $('samplecal').select('.calprevmonth')[0];
            Event.simulateMouse(prev, 'click'); // May
            Event.simulateMouse(prev, 'click'); // April
            Event.simulateMouse(prev, 'click'); // March
            Event.simulateMouse(prev, 'click'); // January
            Event.simulateMouse(prev, 'click'); // Febuary
            Event.simulateMouse(prev, 'click'); // December
            assertEqual('December 2019', $('samplecal').select('.caltitle')[0].innerHTML);
            Event.simulateMouse($('samplecal').select('.calclose')[0], 'click');
            assertNotVisible($('samplecal'));
            Cal.toggleCalendar();
            assertVisible($('samplecal'));
	        $('samplecal').className = '';
	        $('samplecal').addClassName('iscal');
	        var d = new Date(2007,10,1);
	        Cal.setPlannerValue(2007,11,29,"Remove dragons!", 'dragonremove'); // add Remove Dragons to planner
			assertEqual('',$('samplecal').select('.cal_day_0_0_value')[0].innerHTML); // make sure Remove Dragons did NOT show up on the wrong month
	        Cal.setCurrentDate(d); // move to 11/1/2007
			assertEqual('Remove dragons!',$('samplecal').select('.cal_day_4_4_value')[0].firstChild.innerHTML); // see if Remove Dragons appeared in the right spot
			Event.simulateMouse($('samplecal').select('.cal_day_3_4')[0], 'click'); // select 11/22/2007
            assertEqual('22', $('samplecal').select('.dayselected')[0].firstChild.innerHTML);            
        }}

    
 
  });
// ]]>
</script>
</body>
</html>

